<!DOCTYPE html>
<html lang = "en">
<head>
    <meta charset = "UTF-8">
    <title>Title</title>

    <!--=====================================================================-->
    <script>
        // 方便演示而分开
        // 获取所有class='box'的标签
        window.onload = function () {
            let oUl = document.getElementById('ul1');
            let aLi = oUl.getElementsByTagName('li');


            //获取所有class为box的li
            for (let i = 0; i < aLi.length; i++) {
                if (aLi[i].className === 'box') {
                    aLi[i].style.background = 'pink';
                }
            }

            //直接从className也可以获取; 因为原来是没有这个方法的需要手写
            let aItem = document.getElementsByClassName('box');
            for (let i = 0; i < aItem.length; i++) {
                aItem[i].style.background = 'orange'
            }
        }

    </script>
</head>

<body>

<div>
    <ul id="ul1">
        <li class="box"></li>
        <li></li>
        <li class="box"></li>
        <li></li>
        <li class="box"></li>
        <li></li>
        <li></li>
    </ul>

</div>

</body>
</html>